/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {
	
	// 参数配置对象
	const config = vm.vuex_config;
	
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		
		// 基础服务：登录登出、身份信息、菜单授权、切换系统、字典数据等
		lang: (params = {}) => vm.$u.get('/lang/'+params.lang),
		index: (params = {}) => vm.$u.get(config.adminPath+'/index', params),
		login: (params = {}) => vm.$u.post(config.adminPath+'/login', params),
		logout: (params = {}) => vm.$u.get(config.adminPath+'/logout', params),
		authInfo: (params = {}) => vm.$u.get(config.adminPath+'/authInfo', params),
		menuTree: (params = {}) => vm.$u.get(config.adminPath+'/menuTree', params),
		switchSys: (params = {}) => vm.$u.get(config.adminPath+'/switch/'+params.sysCode),
		dictData: (params = {}) => vm.$u.get(config.adminPath+'/sys/dictData/treeData', params),
		
		// 账号服务：验证码接口、忘记密码接口、注册账号接口等
		validCode: (params = {}) => vm.$u.getText('/validCode', params),
		getFpValidCode: (params = {}) => vm.$u.post('/account/getFpValidCode', params),
		savePwdByValidCode: (params = {}) => vm.$u.post('/account/savePwdByValidCode', params),
		getRegValidCode: (params = {}) => vm.$u.post('/account/getRegValidCode', params),
		saveRegByValidCode: (params = {}) => vm.$u.post('/account/saveRegByValidCode', params),
		
		// APP公共服务
		upgradeCheck: () => vm.$u.post('/app/upgrade/check', {appCode: config.appCode, appVersion: config.appVersion}),
		commentSave: (params = {}) => vm.$u.post('/app/comment/save', params),
		
		// 个人信息修改
		user: {
			infoSaveBase: (params = {}) => vm.$u.post(config.adminPath+'/sys/user/infoSaveBase', params),
			infoSavePwd: (params = {}) => vm.$u.post(config.adminPath+'/sys/user/infoSavePwd', params),
			infoSavePqa: (params = {}) => vm.$u.post(config.adminPath+'/sys/user/infoSavePqa', params),
		},
		
		// 员工用户查询
		empUser: {
			listData: (params = {}) => vm.$u.get(config.adminPath+'/sys/empUser/listData', params),
			MyEmployeeInfo: (params = {}) => vm.$u.get(config.adminPath+'/user/getMyEmployeeInfo',params),
		},
		
		// 组织机构查询
		office: {
			treeData: (params = {}) => vm.$u.get(config.adminPath+'/sys/office/treeData', params),
		},
		
		// 增删改查例子
		testData: {
			form: (params = {}) => vm.$u.post(config.adminPath+'/test/testData/form', params),
			list: (params = {}) => vm.$u.post(config.adminPath+'/test/testData/listData', params),
			save: (params = {}) => vm.$u.postJson(config.adminPath+'/test/testData/save', params),
			disable: (params = {}) => vm.$u.post(config.adminPath+'/test/testData/disable', params),
			enable: (params = {}) => vm.$u.post(config.adminPath+'/test/testData/enable', params),
			delete: (params = {}) => vm.$u.post(config.adminPath+'/test/testData/delete', params),
			
		},
		
		
		//订单相关接口
		order:{
			listData1:(params = {}) => vm.$u.post(config.adminPath+'/order/findMyOrder',params),
			listData2:(params = {}) => vm.$u.post(config.adminPath+'/order/findMyDepartmentOrder',params),
			delete: (params = {}) => vm.$u.post(config.adminPath+'/order/delete', params),
			update: (params = {}) => vm.$u.post(config.adminPath+'/order/update', params),
			save: (params = {}) => vm.$u.post(config.adminPath+'/order/save', params),
			addnext: (params = {}) => vm.$u.post(config.adminPath+'/order/addNext', params),
			findall: (params = {}) => vm.$u.post(config.adminPath+'/order/find_all', params),
			getdict: (params = {}) => vm.$u.post(config.adminPath+'/dict/getDict', params),
			gethistory: (params = {}) => vm.$u.get(config.adminPath+'/orderStatus/get_order_history',params),
			findOrderManager: (params = {}) => vm.$u.get(config.adminPath+'/user/findOrderManager',params),
			findDesignerInDepartment: (params = {}) => vm.$u.get(config.adminPath+'/user/findDesignerInDepartment',params),
			//获取安装师傅
			showInstaller: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/showInstaller', params),
			//到报价提审
			QuotationArraignment: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/QuotationArraignment', params),
			//到客户确价
			price_confirmation: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/price_confirmation', params),
			//意向订单
			depositorder: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/deposit_order', params),
			//下单分单获取所有供应商  /supplierOrder/find_all_supplier
			find_all_supplier: (params = {}) => vm.$u.get(config.adminPath+'/supplierOrder/find_all_supplier', params),
			//下单分单提交下一步接口 /orderStatus/splitOrder
			splitOrder: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/splitOrder', params),
			//工厂拆单下一步
			supplierSplitOrder: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/supplierSplitOrder', params),
			//采购下一步
			purchaseToManufacture: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/purchaseToManufacture', params),
			//生产下一步
			manufactureToDelivery: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/manufactureToDelivery', params),
			//物流配送下一步
			deliveryToInstallSending: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/deliveryToInstallSending', params),
			//安装派单下一步
			sendingToInstalling: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/sendingToInstalling', params),
			//交付安装下一步
			installingToCheck: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/installingToCheck', params),
			//交付验收下一步
			checkToEnding: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/checkToEnding', params),
			getdesigndepartment: (params = {}) => vm.$u.get(config.adminPath+'/orderStatus/get_design_department', params),
			Dispatchruler: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/Dispatch_ruler', params),
			Designerbackdrawing: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/Designer_back_drawing', params),
			//设计师回图
			contractconclusive: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/contract_conclusive', params),
			//签字确图下一步
			signature_confirmation: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/signature_confirmation', params),
			//预算提审下一步
			acceptContract: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/acceptContract', params),
			//下单审单下一步
			accept_audit: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/accept_audit', params),
			rejectcontract: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/reject_contract', params),
			rejectaudit: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/reject_audit', params),
			minio: (params = {}) => vm.$u.post(config.adminPath+'/minio/file/upload', params),
			versioncheck: (params = {}) => vm.$u.post(config.adminPath+'/version/getLatestVersion', params),
			//注销账号
			signOut: (params = {}) => vm.$u.post(config.adminPath+'/a/user/logout', params),
			//图片上传
			picture: (params = {}) => vm.$u.postFormData(config.adminPath+'/product/file/upload', params,{ 'content-type': 'multipart/form-data;  boundary=---------------------------7d33a816d302b6'}),
			//柜体查看信息
			getOrderStatus: (params = {}) => vm.$u.post(config.adminPath+'/orderStatus/getOrderStatus', params),
			//获取各个状态图片
			getpic: (params = {}) => vm.$u.get(config.adminPath+'/orderStatus/getpic', params),
			//绑定cid
			bindCid: (params = {}) => vm.$u.get(config.adminPath+'/order/bindCid', params),
		},
		
		//,{ 'content-type': 'multipart/form-data;  boundary=---------------------------7d33a816d302b6'} /orderStatus/getpic
		//文件相关
		minio:{
			// upload:(param = {}) =>
		},
		Notification:{
			sendNotification:(title,content)=>{
				
				let main = plus.android.runtimeMainActivity();
				let pkName = main.getPackageName();
				let uid = main.getApplicationInfo().plusGetAttribute("uid");
				let NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
				//android.support.v4升级为androidx
				if (NotificationManagerCompat == null) {
					NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
				}
				let areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
				// 未开通‘允许通知'权限，则弹窗提醒开通，并点击确认后，跳转到系统设置页面进行设置  
				if (!areNotificationsEnabled) {
					uni.showModal({
						title: '通知权限开启提醒',
						content: '您还没有开启通知权限，无法接受到消息通知，请前往设置！',
						showCancel: false,
						confirmText: '去设置',
						success: function(res) {
							if (res.confirm) {
								let Intent = plus.android.importClass('android.content.Intent');
								let Build = plus.android.importClass("android.os.Build");
								//android 8.0引导  
								if (Build.VERSION.SDK_INT >= 26) {
									let intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
									intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
								} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0  
									let intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
									intent.putExtra("app_package", pkName);
									intent.putExtra("app_uid", uid);
								} else { //(<21)其他--跳转到该应用管理的详情页  
									intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
									let uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
									intent.setData(uri);
								}
								// 跳转到该应用的系统通知设置页  
								main.startActivity(intent);
							}
						}
					});
				}
				// let content = "您有一条新的消息~";
				let body = {
					
				}
				let options = {
					"cover" : false,
					"when" : new Date(),
					'title' : title
				};
				let payload = JSON.stringify(body);
				plus.push.createMessage(content, payload, options);

			},
			enablNotificationPermission(){

			}

		}
	};
	
}

export default {
	install
}